<?php


namespace App\Api;
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS,PATCH');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

use App\Domain\OrderDetail as OrderDetailDomain;
use PhalApi\Api;



class OrderDetail extends Api
{
    public function getRules()
    {
        return array(
            'getOrderInfoByUid' => array(
                'user_id' => array('name' => 'user_id', 'require' => true, 'min' => 1, 'desc' => '用户的id')
            ),
            'getOrderDetailInfoByOid'=>array(
                'order_id' => array('name' => 'order_id', 'require' => true, 'min' => 1,'max' => 150, 'desc' => '订单的id'),
            ),
            'insertOrderDetailInfo' => array(
                'order_id' => array('name' => 'order_id', 'require' => true, 'min' => 1, 'max' => 150, 'source' => 'post', 'desc' => '订单的id'),
                'good_id' => array('name' => 'good_id', 'require' => true, 'min' => 1, 'source' => 'post', 'desc' => '商品的id'),
                'goods_money' => array('name' => 'goods_money', 'require' => true, 'min' => 1,  'source' => 'post', 'desc' => '商品的小计'),
                'goods_num' => array('name' => 'goods_num', 'require' => true, 'min' => 1, 'source' => 'post', 'desc' => '商品的数量'),
            ),
        );
    }

    /**
     * 返回所有订单列表详细信息
     * @desc 查询所有订单列表信息，返回一组json数据
     */
    public function getOrderList(){
        $domain = new OrderDetailDomain();
        $info = $domain->getOrderList();
        return array('info' => $info);
    }

    /**
     * 返回指定用户id的所有订单信息
     * @desc 查询指定用户的所有订单信息
     * 返回一个json集合
     */
    public function getOrderInfoByUid(){
        $user_id = $_GET['user_id'];
        $domain = new OrderDetailDomain();
        $info = $domain->getOrderInfoByUid($user_id);
        return array('info' => $info);
    }
    /**
     * 返回指定订单id的所有订单信息
     * @desc 查询指定订单id的所有订单信息
     * 返回一个json集合
     */
    public function getOrderDetailInfoByOid(){
        $order_id = $_GET['order_id'];
        $domain = new OrderDetailDomain();
        $info = $domain->getOrderDetailInfoByOid($order_id);
        return array('info' => $info);
    }

    /**
     * 创建订单详情接口
     * @desc 创建订单详情
     */
    public function insertOrderDetailInfo(){
        $order_id = $_POST['order_id'];
        $good_id = $_POST['good_id'];
        $goods_num = $_POST['goods_num'];
        $goods_money = $_POST['goods_money'];
        $domain = new OrderDetailDomain();
        $row = $domain->insertOrderDetailInfo($order_id, $good_id, $goods_num, $goods_money);
        return array('row' => $row);
    }
}